Skip to content

Add an error message when both myst_nb and myst_parser included in extensions#713

Open
frankier wants to merge 1 commit intoexecutablebooks:mainfrom
frankier:better-error-with-myst-parser
Open

Add an error message when both myst_nb and myst_parser included in extensions#713
frankier wants to merge 1 commit intoexecutablebooks:mainfrom
frankier:better-error-with-myst-parser

Conversation

@frankier
Copy link
Copy Markdown

@frankier frankier commented Mar 9, 2026

Fixes #653

@bsipocz bsipocz added the bug Something isn't working label Apr 13, 2026
Copy link
Copy Markdown
Member

@bsipocz bsipocz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this looks good on the diff level, I don't see it actually having any effect locally if you change the order of the extensions in the config file.

conf.py:

extensions = [
    'myst_nb',
    'myst_parser',
]

traceback:

Extension error!

Versions
========

* Platform:         darwin; (macOS-12.5.1-arm64-arm-64bit)
* Python version:   3.12.1 (CPython)
* Sphinx version:   9.1.0
* Docutils version: 0.21.2
* Jinja2 version:   3.1.6
* Pygments version: 2.18.0

Last Messages
=============

None.

Loaded Extensions
=================

None.

Traceback
=========

    Traceback (most recent call last):
      File "/Users/bsipocz/.pyenv/versions/3.12.1/lib/python3.12/site-packages/sphinx/cmd/build.py", line 414, in build_main
        app = Sphinx(
              ^^^^^^^
      File "/Users/bsipocz/.pyenv/versions/3.12.1/lib/python3.12/site-packages/sphinx/application.py", line 299, in __init__
        self.setup_extension(extension)
      File "/Users/bsipocz/.pyenv/versions/3.12.1/lib/python3.12/site-packages/sphinx/application.py", line 505, in setup_extension
        self.registry.load_extension(self, extname)
      File "/Users/bsipocz/.pyenv/versions/3.12.1/lib/python3.12/site-packages/sphinx/registry.py", line 569, in load_extension
        metadata = setup(app)
                   ^^^^^^^^^^
      File "/Users/bsipocz/.pyenv/versions/3.12.1/lib/python3.12/site-packages/myst_parser/__init__.py", line 13, in setup
        setup_sphinx(app, load_parser=True)
      File "/Users/bsipocz/.pyenv/versions/3.12.1/lib/python3.12/site-packages/myst_parser/sphinx_ext/main.py", line 37, in setup_sphinx
        app.add_source_suffix(".md", "markdown")
      File "/Users/bsipocz/.pyenv/versions/3.12.1/lib/python3.12/site-packages/sphinx/application.py", line 1726, in add_source_suffix
        self.registry.add_source_suffix(suffix, filetype, override=override)
      File "/Users/bsipocz/.pyenv/versions/3.12.1/lib/python3.12/site-packages/sphinx/registry.py", line 350, in add_source_suffix
        raise ExtensionError(__('source_suffix %r is already registered') % suffix)
    sphinx.errors.ExtensionError: source_suffix '.md' is already registered


The full traceback has been saved in:
/var/folders/9s/070g0pd502q70k3gffpxv8km0000gq/T/sphinx-err-cmvshwrb.log

To report this error to the developers, please open an issue at <https://github.com/sphinx-doc/sphinx/issues/>. Thanks!
Please also report this if it was a user error, so that a better error message can be provided next time.

if "myst_parser" in app.extensions:
raise ValueError(
"Cannot load both myst_nb and myst_parser Sphinx extensions "
"-- load only myst_nb since it includes myst_parser"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe rephrase to be more clear about the action item:

Suggested change
"-- load only myst_nb since it includes myst_parser"
"-- please only list only myst_nb as an extension in your configuration since it includes myst_parser."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unclear error message when both MyST-NB and MyST-parser are enabled

2 participants